{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "851b45b2",
   "metadata": {},
   "source": [
    "# 1.基本操作"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "428c4d3b",
   "metadata": {},
   "source": [
    "## 1.1 创建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3fb16257",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "cb689769",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr1 = np.array([1,2,3])\n",
    "arr1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f9162009",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([49, 38, 30, 73, 93, 44, 90, 39, 25, 78])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr2 = np.random.randint(0,100,size = (10))\n",
    "arr2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ec5b0288",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.82466936,  1.8396129 ,  0.8580169 ,  0.99843934,  0.4628025 ,\n",
       "        0.77621011,  1.84809321, -1.7707937 , -1.26174477, -0.37582213])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr3 = np.random.randn(10)#正态分布\n",
    "arr3\n",
    "#平均值为0，标准差为1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "019e68cc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 以上创建的都是一维数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "58874e7d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ -2,  24,  -2],\n",
       "       [  5,  49,  40],\n",
       "       [-25, -32,  43],\n",
       "       [ -1, -21,  10],\n",
       "       [ -2,  -2, -25]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(-50,50,size = (5,3))\n",
    "#生成了一个5行3列， size 就是数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "caeaeef1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1.],\n",
       "       [1., 1., 1.],\n",
       "       [1., 1., 1.],\n",
       "       [1., 1., 1.],\n",
       "       [1., 1., 1.]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.ones(shape = (5,3))\n",
    "# ones生成的所有数据都是1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "382198c4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.zeros_like(arr3)\n",
    "#传一个参数，a就是一个\n",
    "#创建了10个都是0的数据。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "8a6562bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 3, 6, 9])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 等差数列\n",
    "arr1 = np.arange(0,10,3)\n",
    "arr1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "bfeecc16",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1.,  3.,  5.,  7.,  9., 11., 13., 15., 17., 19., 21., 23., 25.,\n",
       "       27., 29., 31., 33., 35., 37., 39., 41., 43., 45., 47., 49., 51.,\n",
       "       53., 55., 57., 59., 61., 63., 65., 67., 69., 71., 73., 75., 77.,\n",
       "       79., 81., 83., 85., 87., 89., 91., 93., 95., 97., 99.])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linspace(1,99,50)# 1-99 分成50份，刚刚好，1，3，5，7，\n",
    "#这也是一个等差数列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "bc8b110b",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.set_printoptions(suppress=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "3c2f2c03",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([   2.,    4.,    8.,   16.,   32.,   64.,  128.,  256.,  512.,\n",
       "       1024.])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 等比数列\n",
    "np.logspace(1,10,num = 10,base = 2)\n",
    "#加上上面那个之后就不显示科学计数法了。\n",
    "#显示就变成了数字\n",
    "#如何改成整数呢，把那个0改成1. 0,10,num,的0改成1\n",
    "#得到了一个等比数列"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "792bb3fd",
   "metadata": {},
   "source": [
    "#### 查看操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "e118ce63",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[69, 51, 33, 36, 28],\n",
       "        [48,  3, 32, 79, 86],\n",
       "        [15, 23, 20, 23, 77],\n",
       "        ...,\n",
       "        [87, 81, 89,  6,  5],\n",
       "        [60, 30,  9, 61,  0],\n",
       "        [54, 67, 15, 10, 64]],\n",
       "\n",
       "       [[79, 10, 98, 87, 13],\n",
       "        [19,  4, 39, 71, 73],\n",
       "        [32,  0, 40, 55, 16],\n",
       "        ...,\n",
       "        [51, 60, 32, 53, 84],\n",
       "        [47, 39, 75, 25, 26],\n",
       "        [59, 27, 38, 24, 27]],\n",
       "\n",
       "       [[20, 23,  6, 27,  7],\n",
       "        [97, 84,  0, 63, 99],\n",
       "        [12, 76, 34,  8, 72],\n",
       "        ...,\n",
       "        [57,  5, 46, 14,  4],\n",
       "        [50, 65, 56, 86,  2],\n",
       "        [89, 40, 24, 59, 13]],\n",
       "\n",
       "       ...,\n",
       "\n",
       "       [[73, 74, 92, 65, 75],\n",
       "        [ 4, 62,  9, 12, 66],\n",
       "        [41, 72, 66, 22, 32],\n",
       "        ...,\n",
       "        [81, 80, 76, 73, 59],\n",
       "        [40, 51, 73, 95,  4],\n",
       "        [44, 68, 42, 63,  3]],\n",
       "\n",
       "       [[ 6, 44, 80, 67, 35],\n",
       "        [ 3, 61, 14, 78, 57],\n",
       "        [68, 55, 91, 52,  5],\n",
       "        ...,\n",
       "        [37, 24, 16, 80, 72],\n",
       "        [45, 50,  4, 18, 90],\n",
       "        [98, 10, 60, 87, 33]],\n",
       "\n",
       "       [[70, 41, 37, 26, 24],\n",
       "        [34, 32, 69, 39, 82],\n",
       "        [ 7, 60,  8, 79, 19],\n",
       "        ...,\n",
       "        [36, 60, 47, 13,  5],\n",
       "        [67, 23, 93, 39, 37],\n",
       "        [43, 54, 58, 59,  5]]])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.random.randint(0,100,size = (20,16,5))\n",
    "arr\n",
    "#这是一个三维数组，三个中括号那么就是三维的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "49a719d1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(20, 16, 5)"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr.shape\n",
    "#如上所说，如果遇到一个特别大的数组，不知道它的类型，\n",
    "#那么就可以， arr.shape 就能查看到它的一个数组数据\n",
    "# 20 行，16列，每行的数是5，每一行每一列的数据交叉点是5个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "db92c26c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[79, 35, 23, 70, 34],\n",
       "        [ 5, 53, 95,  4, 47],\n",
       "        [83, 85, 56, 76,  4],\n",
       "        [44, 55, 55,  3, 43],\n",
       "        [15, 54, 76, 24, 40],\n",
       "        [29, 30, 18, 91, 49]],\n",
       "\n",
       "       [[ 2, 90, 15, 60, 95],\n",
       "        [20, 65, 57,  9, 14],\n",
       "        [44, 65, 37, 39, 14],\n",
       "        [49, 82, 46, 82, 36],\n",
       "        [18, 83, 85, 18, 68],\n",
       "        [15, 55, 63, 80, 41]]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.random.randint(0,100,size = (2,6,5))\n",
    "arr\n",
    "# 中间那个6虽然指的是6列，但是其实相当于6行\n",
    "# 5的话每一行5个数\n",
    "#三维就可以看 arr.shape就可以了，看形状就可以了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "02b4deb0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[19, 87, 31, 14,  8, 25],\n",
       "       [81, 49, 76, 15, 84, 65],\n",
       "       [66, 46, 25,  0, 15, 69],\n",
       "       [69, 72, 67,  5, 39, 70],\n",
       "       [39, 56, 72, 26, 64, 71]])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.random.randint(0,100,size = (5,6))\n",
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "0cc8a349",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[[13, 23, 74, 89, 50, 13, 13, 46],\n",
       "         [78, 85, 21, 28, 78, 62, 41, 46],\n",
       "         [40, 72,  9, 87, 25, 67, 12, 37],\n",
       "         [82, 77, 43, 61, 62, 53, 87, 99],\n",
       "         [98, 47, 69, 97, 96, 62, 12, 22],\n",
       "         [76, 18, 23,  6, 44, 78, 16, 77]],\n",
       "\n",
       "        [[30,  5, 31, 25, 31,  5, 15, 47],\n",
       "         [29,  0, 81, 10, 95, 36, 82,  2],\n",
       "         [26, 57,  3, 18,  1, 93, 88, 69],\n",
       "         [35, 67, 36, 79, 82, 65, 99, 68],\n",
       "         [53,  7, 51, 79,  6, 70, 49,  4],\n",
       "         [28, 24, 47, 99,  7, 97, 84,  3]],\n",
       "\n",
       "        [[39, 41, 34, 56, 68, 65, 24, 66],\n",
       "         [70, 16, 97, 11, 14, 65, 16, 51],\n",
       "         [73, 19, 52, 36, 96,  5, 71, 50],\n",
       "         [62, 18, 53, 46, 10, 15, 71, 64],\n",
       "         [81, 34, 33,  6, 27, 29, 48, 28],\n",
       "         [36,  7,  7, 65, 25, 92, 24, 60]],\n",
       "\n",
       "        [[77, 65,  8, 31, 20, 21, 18, 22],\n",
       "         [24, 20, 25, 98, 33, 60, 45, 23],\n",
       "         [53, 80, 94, 11, 85, 71, 15, 25],\n",
       "         [59, 58, 51, 55, 97, 91, 95, 17],\n",
       "         [ 5, 48, 77, 33, 70, 70, 79, 75],\n",
       "         [87,  8, 85, 85, 28, 81, 36, 71]],\n",
       "\n",
       "        [[68, 12, 34, 63, 83, 67, 13, 20],\n",
       "         [ 9, 59, 34, 52, 22,  5, 98,  1],\n",
       "         [83, 20, 93, 30, 16, 77, 26, 64],\n",
       "         [76, 42, 18, 34, 76, 89, 10, 19],\n",
       "         [72, 70, 92, 30, 12, 38,  8, 12],\n",
       "         [93, 74, 22, 71, 59, 56, 91, 14]]],\n",
       "\n",
       "\n",
       "       [[[75, 35, 99, 33, 67, 61, 88, 66],\n",
       "         [50, 88, 76, 90, 50, 26, 26, 80],\n",
       "         [51, 42, 21, 54, 38, 40, 26, 23],\n",
       "         [76, 80, 99, 77, 19, 79,  8, 22],\n",
       "         [ 4, 28,  7, 54, 35, 91, 48, 47],\n",
       "         [97, 43, 96, 25, 69, 89, 59, 75]],\n",
       "\n",
       "        [[93, 85, 28, 84, 17, 29, 13, 95],\n",
       "         [14, 70, 39, 75, 16, 24, 44, 36],\n",
       "         [83, 95, 57, 17, 41, 39, 99, 40],\n",
       "         [48, 61, 94, 65, 74, 34, 80, 69],\n",
       "         [37, 40, 26, 37, 24, 22, 35, 53],\n",
       "         [87, 17, 57, 92, 57, 41, 76, 70]],\n",
       "\n",
       "        [[97, 99, 62, 92, 20, 74, 43, 88],\n",
       "         [48, 68,  6, 43, 30, 33,  4,  4],\n",
       "         [16,  8, 78, 72, 61, 33, 58, 59],\n",
       "         [ 1, 66, 79, 90,  8, 49, 33, 58],\n",
       "         [24, 21, 87, 13, 14, 86, 97, 79],\n",
       "         [28, 29, 17,  7, 13, 74,  3, 26]],\n",
       "\n",
       "        [[90, 15,  8, 79, 98, 43, 34, 60],\n",
       "         [44, 90, 76,  8, 25, 75, 27, 43],\n",
       "         [77,  6, 22, 31, 45,  7, 40, 94],\n",
       "         [32, 11, 36, 78, 78, 57, 57, 49],\n",
       "         [ 9, 97, 68, 57, 43, 85, 92,  7],\n",
       "         [17, 73, 32, 27, 15, 87, 46, 61]],\n",
       "\n",
       "        [[69, 74, 91, 50, 56, 96, 43, 50],\n",
       "         [99, 24,  3, 59, 34, 66,  7, 94],\n",
       "         [84, 92, 43, 97, 73, 66, 30, 40],\n",
       "         [60, 35, 96, 82, 22, 65, 44, 82],\n",
       "         [98, 27, 41,  9, 76, 91, 22, 52],\n",
       "         [66, 17, 32,  3, 58, 36, 68,  6]]],\n",
       "\n",
       "\n",
       "       [[[51, 30, 89, 81, 91, 97,  8, 59],\n",
       "         [67, 59, 22, 55, 11, 11, 46, 66],\n",
       "         [ 1, 39, 60, 22, 54, 41, 21, 37],\n",
       "         [93, 83, 69, 21, 52, 75, 98, 52],\n",
       "         [58,  7, 32, 19, 94, 15,  8, 57],\n",
       "         [87, 43, 20, 34, 29, 68, 35, 82]],\n",
       "\n",
       "        [[51, 94, 45, 34, 82, 73, 52, 40],\n",
       "         [16, 93, 11, 77, 40, 68, 13, 55],\n",
       "         [70, 60, 42, 39, 45, 74,  8,  7],\n",
       "         [56, 98, 24, 70,  0,  9, 18, 14],\n",
       "         [10, 48, 63, 21, 78, 76, 40, 71],\n",
       "         [49, 27, 37, 45, 66, 11, 16, 73]],\n",
       "\n",
       "        [[90,  3, 79, 67, 86, 96, 25, 70],\n",
       "         [92, 77, 13, 13, 70, 88, 28, 32],\n",
       "         [45,  6, 99, 94, 41, 85, 73, 35],\n",
       "         [65, 61, 77, 17, 50, 90, 28, 79],\n",
       "         [18, 53, 73,  8, 75, 35, 56, 21],\n",
       "         [96, 97, 77, 56, 97, 18, 69,  9]],\n",
       "\n",
       "        [[65,  1, 77, 47, 60, 22, 99, 98],\n",
       "         [33, 97, 14, 32, 39, 99, 17, 60],\n",
       "         [79, 88,  9, 29, 65, 31,  0, 72],\n",
       "         [57, 93,  9, 27, 31,  3, 22, 65],\n",
       "         [86, 24, 23, 87, 47, 87, 39, 20],\n",
       "         [97, 88, 72, 66, 87, 66, 36,  5]],\n",
       "\n",
       "        [[97, 69, 11,  6, 92, 35, 47, 49],\n",
       "         [61, 15, 21, 93, 91, 64,  0, 38],\n",
       "         [39, 67,  4, 34, 40,  8, 31, 86],\n",
       "         [36,  9, 19, 58, 49,  1, 45, 69],\n",
       "         [86, 50, 55, 57, 37, 57, 37, 24],\n",
       "         [61, 19, 81, 58, 67, 95, 30,  5]]]])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.random.randint(0,100,size = (3,5,6,8))\n",
    "arr\n",
    "#比如说四维数组，都是一样的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "931cd31d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3, 5, 6, 8)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "bb3ec5b3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('int32')"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看数据类型\n",
    "arr.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "92223ae8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "720"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr.size\n",
    "# 一共多少个数，720."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "2b3af2bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "720"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3*5*6*8\n",
    "#为什么 720？  3*5*6*8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "3565f279",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#也可以查看数据的维度\n",
    "arr.ndim"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "60cdc6f3",
   "metadata": {},
   "source": [
    "#### 文件操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "f1afb1b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# IO操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "c9059ef9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.58435914, 0.51241512, 0.39947009, 0.29806727, 0.77606518],\n",
       "       [0.00979123, 0.18822382, 0.08123241, 0.33952356, 0.69973228],\n",
       "       [0.27757281, 0.09857063, 0.54564505, 0.60803822, 0.56562629]])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr1 = np.random.random(size = (3,5))\n",
    "arr1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "4ef72718",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.save('./arr1',arr1)\n",
    "#文件后缀，默认是npz。\n",
    "#此时返回的话，会出现一个  arr1.npy的文件。就会直接保存了。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "87ccc4d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "#如果要声明的话，可以这样写\n",
    "np.save(file = './arr1',arr = arr1)\n",
    "#要同时声明，如果一个声明，一个不声明，就会报错\n",
    "#np.save(file = './arr1',arr1)  ,比如这样"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "1451646c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.58435914, 0.51241512, 0.39947009, 0.29806727, 0.77606518],\n",
       "       [0.00979123, 0.18822382, 0.08123241, 0.33952356, 0.69973228],\n",
       "       [0.27757281, 0.09857063, 0.54564505, 0.60803822, 0.56562629]])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#  但是保存的那个 arr1.npy虽然打不开，但是我们可以读取\n",
    "np.load('./arr1.npy')\n",
    "#就会出现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "e913017c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([   2.,    4.,    8.,   16.,   32.,   64.,  128.,  256.,  512.,\n",
       "       1024.])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr2 = np.logspace(1,10,num = 10,base = 2)#创建等比数列\n",
    "arr2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "cbe8ddf1",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.savez('./file2',arr_x = arr1,arr_y = arr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "df20eb23",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.58435914, 0.51241512, 0.39947009, 0.29806727, 0.77606518],\n",
       "       [0.00979123, 0.18822382, 0.08123241, 0.33952356, 0.69973228],\n",
       "       [0.27757281, 0.09857063, 0.54564505, 0.60803822, 0.56562629]])"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.load('./file2.npz')['arr_x']\n",
    "#加载 np.load"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "60a27549",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([   2.,    4.,    8.,   16.,   32.,   64.,  128.,  256.,  512.,\n",
       "       1024.])"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.load('./file2.npz')['arr_y']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "b5096baf",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.savetxt('./arr1.txt',arr1,delimiter = ',',fmt = '%.5f')# 加f标识float，加e表示科学计数法\n",
    "# 表示浮点数，e代表科学计数法\n",
    "#保存成txt 文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "fe8a842a",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.savetxt('./arr1.csv',arr1,delimiter = ':',fmt = '%.5f')\n",
    "# 这个文件和上面txt 间隔有差异，\n",
    "# 一个是分号，一个是逗号。\n",
    "\n",
    "# csv这个数据可以自动生成 Excl的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "d7dc7cd6",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.savetxt('./arr2.csv',arr1,delimiter = ',',fmt = '%.5f')\n",
    "\n",
    "# 两个区别在于 上面那个是 用 : 号隔开， 下面用的是 ,号隔开。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0e7f7d9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
